<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

	<head>

		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <!-- 移动端视口说明 -->
		<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">

		<title><?php echo C('WEB_TITLE');?></title>

		<link rel="stylesheet" href="/Public/css/common.css"/>

		<link rel="stylesheet" href="/Public/js/layui/css/layui.css"/>

        <link rel="stylesheet prefetch" href="/Public/js/photoswipe/photoswipe.css">

        <link rel="stylesheet prefetch" href="/Public/js/photoswipe/default-skin/default-skin.css">

		<link rel="stylesheet" href="/Public/mobile/css/crm-mobile-terminal.css"/>
		<link rel="stylesheet" href="/Public/js/jeDate/skin/jedate.css">
		<link rel="stylesheet" href="/Public/js/mobile-date/mobile-date.css">
		<link rel="stylesheet" href="/Public/js/mobileSelect/mobileSelect.css">

        <link rel="stylesheet" href="<?php echo C('MOBILE_ICON_HTTP');?>"/>

		<script type="text/javascript" >

			const moduleName = "<?php echo (MODULE_NAME); ?>";

		</script>

		<script type="text/javascript" src="/Public/js/jquery-1.9.1.min.js"></script>

		<script type="text/javascript" src="/Public/js/cookie/jquery.cookie.js"></script>

		<script type="text/javascript" src="/Public/js/lang/<?php echo (getStrToLower(cookie('think_language'))); ?>.js"></script>

		<script type="text/javascript" src="/Public/js/layer/layer.js"></script>

		<script type="text/javascript" src="/Public/js/layui/layui.js"></script>

		<script type="text/javascript" src="/Public/js/WeChat/wechatglobal.js"></script>

		<script type="text/javascript" src="/Public/js/WeChat/wechatupload.js"></script>

		<script type="text/javascript" src="/Public/js/photoswipe/photoswipe.min.js"></script>

		<script type="text/javascript" src="/Public/js/photoswipe/photoswipe-ui-default.min.js"></script>

        <script type="text/javascript" src="/Public/js/WeChat/iscroll.js"></script>

		<script type="text/javascript" src="/Public/js/mobile-date/mobile-date.js"></script>
		
		<script type="text/javascript" src="/Public/js/jeDate/src/jedate.js"></script>
		
		<script type="text/javascript" src="/Public/mobile/js/crm-window.js"></script>
		
		<script type="text/javascript" src="/Public/js/feeldesk-slide.js"></script>

		<script type="text/javascript" src="/Public/js/photoswipe/photohtml.js"></script>

		<style type="text/css">

            body{background-color: #fafafa}

        </style>

		<script type="text/javascript" src="/Public/js/uni.webview.1.5.2.js"></script>

		<script type="text/javascript">

			//整合版：当前页为首页发送消息给整合系统并更改页面样式
			if(self!=top)
			{
				var isIframe=true;
			}

			var isFeelecApp = false;

			if(isIframe)
			{
				document.addEventListener("UniAppJSBridgeReady", function ()
				{
					uniPostHome();
				});
			}

			document.addEventListener('UniAppJSBridgeReady', function()
			{
				uni.getEnv(function(res)
				{
					if (res.plus)//res.h5
					{
						isFeelecApp = true;

						uniPostHome();
					}
				});
			});

			function uniPostHome()
			{
				var think_controller = "<?php echo (CONTROLLER_NAME); ?>";
				var think_action = "<?php echo (ACTION_NAME); ?>";

				if(think_controller+"/"+think_action == "Index/index")
				{
					uni.postMessage({
						data: {
							isHome: true
						}
					});
				}
				else
				{
					uni.postMessage({
						data: {
							isHome: false
						}
					});
				}
			}

		</script>

	</head>

    <body>



<div class="feeldesk" id="formWrapper">

    <header>

        <div class="menu-header">

            <a href="javascript:history.go(-1)" class="iconfont icon-back-left back"></a>

            <div class="header-title"><?php echo L('ADD_CONTACTS');?></div>

            <a href="javascript:" class="header-right" id="submitForm"><?php echo L('COMPLETE');?></a>

        </div>

    </header>

    <div class="feeldesk-main no-footer-main pd0">

        <form action="<?php echo U('Customer/create_contacter',['id'=>encrypt($customer_id,'CUSTOMER'),'detailtype'=>encrypt($detailtype,'CUSTOMER')]);?>" id="feeldeskForm" method="post" class="layui-form">

			<?php $ft = 0; $reg = 0; ?>

            <div class="feeldesk-form pd5">

				<?php if(empty($customer_id)): ?><div class="feeldesk-form-item">

						<div class="feeldesk-form-block">

							<span class="red required-icon vw6">*</span>

							<input type="hidden" name="contacter[customer_id]" value="" id="sCustomerInput" />

							<span class="sCustomerName" id="sCustomerName"></span>

							<span class="selectCustomerBtn" id="selectCustomer"> + <?php echo L('SELECT_CUSTOMER');?></span>

						</div>

					</div>

				<?php else: ?>

					<input type="hidden" name="contacter[customer_id]" value="<?php echo ($customer_id); ?>" /><?php endif; ?>

				<?php if(is_array($contacterform)): $i = 0; $__LIST__ = $contacterform;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><!-- 字段未设置查看范围或当前用户角色在查看范围内 -->
					<?php if(!$vo['role_id'] || in_array($mobile['role_id'],explode(',',$vo['role_id']))): if(($vo["form_type"]) == "region"): $reg++; ?>

						<?php echo W('Region/getRegion',['contacter_form',$vo,$reg]);?>

					<?php else: ?>

					 <div class="feeldesk-form-item relative">

						<div class="feeldesk-form-block">

							<?php if(($vo["is_required"]) == "0"): ?><span class="red required-icon">*</span><?php endif; ?>

							<?php if(($vo["form_type"]) == "text"): ?><!-- 单行文本框 -->
								<input type="text" name="contacter_form[<?php echo ($vo["form_name"]); ?>]" value="" placeholder="<?php echo ($vo["form_description"]); ?>" class="feeldesk-input"/><?php endif; ?>

							<?php if(($vo["form_type"]) == "phone"): ?><!-- 手机 -->
								<input type="text" onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && event.keyCode<48 || event.keyCode>57) event.returnValue=false" name="contacter_form[<?php echo ($vo["form_name"]); ?>]" value="" placeholder="<?php echo ($vo["form_description"]); ?>" class="feeldesk-input"/><?php endif; ?>

							<?php if(($vo["form_type"]) == "email"): ?><!-- 邮箱 -->
								<input type="text" name="contacter_form[<?php echo ($vo["form_name"]); ?>]" value="" placeholder="<?php echo ($vo["form_description"]); ?>" class="feeldesk-input"/><?php endif; ?>

							<?php if(($vo["form_type"]) == "number"): ?><!-- 数字 -->
								<input type="number" onKeyPress="if (event.keyCode!=46 && event.keyCode!=45 && event.keyCode<48 || event.keyCode>57) event.returnValue=false" name="contacter_form[<?php echo ($vo["form_name"]); ?>]" value="" placeholder="<?php echo ($vo["form_description"]); ?>" class="feeldesk-input"/><?php endif; ?>

							<?php if(($vo["form_type"]) == "decimal"): ?><!-- 小数 -->
								<input type="text" name="contacter_form[<?php echo ($vo["form_name"]); ?>]" value="" placeholder="<?php echo ($vo["form_description"]); ?>" class="feeldesk-input"/><?php endif; ?>

							<?php if(($vo["form_type"]) == "select"): ?><!-- 下拉菜单 -->
								<select name="contacter_form[<?php echo ($vo["form_name"]); ?>]" lay-filter="">

									<option value=""><?php echo ($vo["form_description"]); ?></option>

									<?php if(is_array($vo["option"])): foreach($vo["option"] as $key=>$op): ?><option value="<?php echo ($op); ?>"><?php echo ($op); ?></option><?php endforeach; endif; ?>

								</select><?php endif; ?>
							
							<?php if(($vo["form_type"]) == "select_text"): $st++; ?>
								<!-- 下拉填写 -->
								<?php echo W('Update/selectTextForm',['contacter',$vo,$st]); endif; ?>

							<?php if(($vo["form_type"]) == "checkbox"): ?><!-- 多选 -->
                                <div class="feeldesk-input feeldesk-form-check checkbox">

                                    <span class='gray9'><?php echo ($vo["form_description"]); ?></span>

                                    <i class="feeldesk-edge"></i>

                                </div>

                                <ul class="feeldesk-option-panel hidden checkboxPanel">

                                    <?php if(is_array($vo["option"])): $i = 0; $__LIST__ = $vo["option"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$op): $mod = ($i % 2 );++$i;?><li data-value="<?php echo ($op); ?>">

                                            <input type="checkbox" name="contacter_form[<?php echo ($vo["form_name"]); ?>][]" value="<?php echo ($op); ?>"/>

                                            <div class="feeldesk-option">

                                                <span class="feeldesk-option-title"><?php echo ($op); ?></span>

                                                <span class="iconfont icon-check"></span>

                                            </div>

                                        </li><?php endforeach; endif; else: echo "" ;endif; ?>

                                </ul><?php endif; ?>

							<?php if(($vo["form_type"]) == "radio"): ?><!-- 单选 -->
								<div class="feeldesk-input feeldesk-form-check radio name-radio"><span><?php echo ($vo["form_description"]); ?></span><i class="feeldesk-edge"></i></div>

								<ul class="feeldesk-option-panel radioPanel hidden">

									<input type="hidden" name="contacter_form[<?php echo ($vo["form_name"]); ?>]" value=""/>

									<?php if(is_array($vo["option"])): $i = 0; $__LIST__ = $vo["option"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$op): $mod = ($i % 2 );++$i;?><li data-name="<?php echo ($op); ?>" data-value="<?php echo ($op); ?>">

										<div class="feeldesk-option">

											<span class="feeldesk-option-title"><?php echo ($op); ?></span>

											<span class="iconfont icon-check"></span>

										</div>

									</li><?php endforeach; endif; else: echo "" ;endif; ?>

								</ul><?php endif; ?>

							<!-- 文本域 -->
							<?php if(($vo["form_type"]) == "textarea"): ?><textarea name="contacter_form[<?php echo ($vo["form_name"]); ?>]" class="feeldesk-input feeldesk-textarea" placeholder="<?php echo ($vo["form_description"]); ?>"></textarea><?php endif; ?>

							<!-- 时间控件 -->
							<?php if(($vo["form_type"]) == "date"): $ft++; ?>

								<input type="text" name="contacter_form[<?php echo ($vo["form_name"]); ?>]" value="" placeholder="<?php echo ($vo["form_description"]); ?>" id="datetime<?php echo $ft; ?>" class="feeldesk-input" readonly />

                                <script type="text/javascript">

                                    $(function()
                                    {
                                        jeDate("#datetime<?php echo $ft; ?>",{
											minDate:"1900-01-01",              //最小日期
											maxDate:"2099-12-31",              //最大日期
											method:{
												choose:function (params) {

												}
											},
											format: "YYYY-MM-DD hh:mm:ss"
										});
                                    })

                                </script><?php endif; ?>

						</div>

					</div><?php endif; endif; endforeach; endif; else: echo "" ;endif; ?>



            </div>

        </form>

    </div>

</div>

<div class="sCustomer" id="sCustomer">

	<div class="sCustomer-shade"></div>

	<div class="sCustomer-content">

		<header>

			<a href="javascript:" class="sCustomer-cancel" id="sCustomerCancel"><?php echo L('CANCEL');?></a>

			<div class="sCustomer-search">

				<i class="iconfont icon-search"></i>

				<input type="text" name='' id="sCustomerSearch" placeholder="<?php echo L('CLIENT_NAME');?>">

			</div>

			<a href="javascript:" class="sCustomer-ensure" id="sCustomerDone"><?php echo L('COMPLETE');?></a>

		</header>

		<main id="sCustomerItem"><div class="no-match"><?php echo L('NO_MATCH');?></div></main>

	</div>

</div>

<script>

	var no_more = "<?php echo L('NO_MORE');?>";

	var selectActionUrl = '/<?php echo (CONTROLLER_NAME); ?>/<?php echo (ACTION_NAME); ?>';

	var selectAction = '<?php echo (ACTION_NAME); ?>';

	$('#selectCustomer').click(function()
	{
		var company_id = '<?php echo ($mobile["company_id"]); ?>';

		$('#sCustomer').toggleClass('sCustomer-show');

		if($('.sCustomer-show').length > 0)
		{
			togetCustomerList();
		}

		$('#sCustomerCancel').unbind('click').on('click',function()
		{
			$('#sCustomer').toggleClass('sCustomer-show');
		});

		$('#sCustomerSearch').keyup(function ()
		{
			var value = $(this).val();

			var sCustomer = $('.sCustomer-item');

			var sCustomerItem = $('#sCustomerItem');

			if(value)
			{
				togetCustomerList(value);
			}
			else
			{
				togetCustomerList();
			}
		});
	})

	function togetCustomerList(keyword='')
	{
		$("#sCustomerItem").empty();

		layui.use('flow', function ()
		{
			var flow = layui.flow;

			flow.load(
			{
				elem: '#sCustomerItem',
				end: no_more,
				done: function (page, next)
				{
					$.post("<?php echo U('AjaxRequest/getCustomerList');?>?request=sCustomer&keyword="+keyword+"&p=" + page, function (data)
					{
						var lis = [];

						var item = '';

						$.each(data.data,function(k,v)
						{
							item +="<div class='sCustomer-item' data-value='"+v.customer_id+"' data-name='"+v.detail.name+"'>" +
								"<span class='ticket-title ellipsis'>"+ v.detail.name+"</span>" +
								"<span class='iconfont icon-check'></span></div>"
						});

						lis.push(item);

						next(lis.join(''), page < data.pages);

						$('.sCustomer-item').unbind('click').on('click',function()
						{
							$(this).find('span.iconfont').addClass('icon-radio-checked').parent().siblings().find('span').removeClass('icon-radio-checked');
						})

					},'JSON');
				}
			});
		});

		$('#sCustomerDone').unbind('click').on('click',function()
		{
			var customer_id = $('.sCustomer-item').find('span.icon-radio-checked').parent().data('value');

			var customer_name = $('.sCustomer-item').find('span.icon-radio-checked').parent().data('name');

			$('#sCustomerInput').val(customer_id);

			$('#sCustomerName').html(customer_name);

			if(selectAction == 'create_follow')
			{
				$.ajax(
				{
					url:"<?php echo U('AjaxRequest/getContacter');?>",

					type:'POST',

					async: false,

					data:{'customer_id':customer_id},

					datatype:'json',

					success:function(data)
					{
						$('#ContacterList').html(data.html);

						layui.use('form', function() {

							var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

							form.render('select');

						});

						$('#ContacterList').parents('.feeldesk-form-item').removeClass('hidden');
					},
					error:function()
					{
					   //layer.msg('保存排序异常');
					}
				});
			}

			if($.inArray(selectActionUrl,['/Account/create','/Receipt/create','/Invoice/create']) != -1)
			{
				$.ajax({
					url:"<?php echo U('AjaxRequest/getContract');?>",
					type:'POST',
					async: false,
					data:{'customer_id':customer_id,'type':'option'},
					datatype:'json',
					success:function(data)
					{
						$('#contractList').html(data.html);

						layui.use('form', function() {

							var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

							form.render('select');

						});
					}
				});

				if(selectActionUrl == '/Invoice/create')
				{
					$.ajax({
						url:"<?php echo U('AjaxRequest/getCustomerInvoiceInfo');?>",
						type:'POST',
						async: false,
						data:{'customer_id':customer_id},
						datatype:'json',
						success:function(data)
						{
							$('#InvoiceInfoList').html(data.html);

							layui.use('form', function() {

								var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

								form.render('select');

							});
						}
					});
				}
			}

			/*if(selectActionUrl == '/Order/create')
			{
				$.ajax({
					url:"<?php echo U('AjaxRequest/getContract');?>",
					type:'POST',
					async: false,
					data:{'customer_id':customer_id},
					datatype:'json',
					success:function(data)
					{
						$('#selectContract span').html('<?php echo L('ASSOCIATED_CONTRACT');?>');

						$('#sContractList').hide();

						$('#sContractList').html(data.html);

						checkboxClick();

					},
					error:function()
					{

					}
				});
			}*/

			if(selectActionUrl == '/Contract/create')
			{
				$.ajax({
					url:"<?php echo U('AjaxRequest/getOpportunity');?>",
					type:'POST',
					async: false,
					data:{'customer_id':customer_id},
					datatype:'json',
					success:function(data)
					{
						$('#sOpportunitySelect').html(data.html);

						layui.use('form', function() {

							var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功

							form.render('select');

						});
					},
					error:function()
					{

					}
				});
			}

			$('#sCustomer').toggleClass('sCustomer-show');
		})
	}

	function checkboxClick()
	{
		$(".checkbox").unbind('click').on('click',function()
		{
			var checkbox = $(this);

			$(this).toggleClass('feeldesk-form-checked').next('.feeldesk-option-panel').slideToggle('fast');

			$(this).parents('.feeldesk-form-item').siblings().find('.feeldesk-input').removeClass('feeldesk-form-checked').next('.feeldesk-option-panel').slideUp('fast');

			$(".checkboxPanel").find('li').on('click',function()
			{
				var value = $(this).data('value');

				$(this).find('span.iconfont').toggleClass('icon-checkbox-checked');

				var oldValue = checkbox.find('span').text();

				var content = '';

				if($(this).find('span.iconfont').hasClass('icon-checkbox-checked'))
				{
					$(this).find("input").prop('checked',true);

					content = addContent(oldValue,value);
				}
				else
				{
					$(this).find("input").prop('checked',false);

					content = removeContent(oldValue,value);
				}

				$(this).parent('.checkboxPanel').prev('.checkbox').find('span').text(content);
			});
		});
	}

</script>